<template>
	<view class="content">
		<view class="user">
			<image src="../../static/img/user.svg"></image>
			<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
				<image class="avatar" :src="avatarUrl"></image>
			</button>
		</view>
		<input type="nickname" v-model="nickname" @change="onChange" class="weui-input" placeholder="请输入昵称" />
		<span class="confirm" @tap="submit">确认</span>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatarUrl: '',
				nickname: ''
			}
		},
		mounted() {
			this.avatarUrl = uni.getStorageSync('avatarUrl')
			this.nickname = uni.getStorageSync('nickname')
		},
		methods: {
			onChooseAvatar(e) {
				this.avatarUrl = e.detail.avatarUrl
			},
			onChange(e) {
				this.nickname = e.detail.value
			},
			submit() {
				if (!this.avatarUrl) {
					uni.showToast({
						icon: 'error',
						title: '请选择头像',
					});
					return
				}
				console.log(1111, this.nickname)
				if (!this.nickname) {
					uni.showToast({
						icon: 'error',
						title: '请输入昵称',
					});
					return
				}
				uni.setStorageSync('avatarUrl', this.avatarUrl)
				uni.setStorageSync('nickname', this.nickname)
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	
	.content {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		padding-bottom: calc(env(safe-area-inset-bottom) + 200rpx);
		background: #fff;
		height: 100vh;
	}
	.avatar-wrapper {
		width: 158rpx;
		height: 158rpx;
		border-radius: 28rpx;
		overflow: hidden;
		background: #e5e5e5;
		padding: 0;
		.avatar {
			width: 158rpx;
			height: 158rpx;
			border-radius: 28rpx;
		}
	}
	
	.user {
		position: relative;
		image {
			width: 128rpx;
			height: 128rpx;
			position: absolute;
			transform: translate3d(-50%,-50%,0);
			top: 50%;
			left: 50%;
			z-index: 999;
		}
	}

	.weui-input {
		padding: 30rpx 0;
		text-align: center;
	}
	
	.confirm {
		width: 580rpx;
		height: 84rpx;
		line-height: 84rpx;
		background: #dc261b;
		font-size: 28rpx;
		text-align: center;
		color: #fff;
		border-radius: 50rpx;
		margin-top: 30rpx;
	}

	
</style>
